/**
 * 
 */
package com.xxxx.game;

import java.util.Vector;

/**
 * @author HuXiaolong
 *
 */
public class CompactAnimation extends AnimationBasic
{
	private Vector<IAnimation> mAnimations = new Vector<IAnimation>();

	public CompactAnimation()
	{
	}

	public void add(IAnimation anim)
	{
		mAnimations.add(anim);
	}

	public void remove(IAnimation anim)
	{
		mAnimations.remove(anim);
	}
	
	public Vector<IAnimation> getAnimations()
	{
		return mAnimations;
	}

	@Override
	public boolean update(ISprite sprite)
	{
		Vector<IAnimation> toremove = new Vector<IAnimation>();
		toremove.add(null);
		for (int i = 0; i < mAnimations.size(); ++ i)
		{
			IAnimation x = mAnimations.get(i);
			if (x != null && !x.update(sprite))
			{
				IAnimation n = x.getNext();
				if (n != null)
				{
					mAnimations.set(i, n);
				}
				else
				{ // don't need update it again
					toremove.add(x);
				}
			}
		}
		
		mAnimations.removeAll(toremove);
		return !mAnimations.isEmpty();
	}

	@Override
	public boolean isMoving()
	{
		for (int i = 0; i < mAnimations.size(); ++ i)
		{
			IAnimation x = mAnimations.get(i);
			if (x != null && x.isMoving())
			{
				return true;
			}
		}
		return false;
	}

	@Override
	public String getName()
	{
		// TODO Auto-generated method stub
		return "CompactAction";
	}
}
